package com.rd.student.jike.class2.lihongming.Solution713;

import java.util.HashMap;

/**
 * @Auther:Heinrich
 * @Date:2023/7/14-07-14-19:42
 * @Description:com.rd.student.jike.class2.lihongming.Solution713
 * @version:1.0
 */
public class Question10 {
    public static int rome(String romeNum){
        int count =0;
        for (int i = 0; i < romeNum.length(); i++) {
            switch (romeNum.charAt(i)){
                case 'M':
                    count += 1000;
                    break;
                case 'D':
                    count += 500;
                    break;
                case 'C':
                    count += 100;
                    if (i<romeNum.length()-1&&romeNum.charAt(i + 1) == 'D') {
                        count += 300;
                        i++;
                    } else if (i<romeNum.length()-1&&romeNum.charAt(i + 1) == 'M') {
                        count += 800;
                        i++;
                    }
                    break;
                case 'L':
                    count += 50;
                    break;
                case 'X':
                    count += 10;
                    if (i<romeNum.length()-1&&romeNum.charAt(i + 1) == 'L') {
                        count += 30;
                        i++;
                    } else if (i<romeNum.length()-1&&romeNum.charAt(i + 1) == 'C') {
                        count += 80;
                        i++;
                    }
                    break;
                case 'V':
                    count += 5;
                    break;
                case 'I':
                    count +=1;
                    if (i<romeNum.length()-1&&romeNum.charAt(i + 1) == 'V') {
                        count += 3;
                        i++;
                    } else if (i<romeNum.length()-1&&romeNum.charAt(i + 1) == 'X') {
                        count += 8;
                        i++;
                    }
                    break;
                default:
                    break;

            }
        }
        return count;
    }

    public static void main(String[] args) {
        String str= "MCMXCIV";
        System.out.println(rome(str));
    }
}
